<template>
  <basic-container>
    <div id="Aftermarket">
      <h3>售后服务</h3>
      <el-select
        style="margin-right: 15px"
        v-model="shopnamevalue"
        filterable
        clearable
        placeholder="请选择商品类型"
        @change="search"
      >
        <el-option
          v-for="item in shopname"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <el-button type="primary" style="margin-top: 15px" @click="preservation"
        >保存</el-button
      >
      <br />
      <textarea
        class="details"
        :placeholder="title"
        rows="10"
        v-model="version"
      ></textarea>
    </div>
  </basic-container>
</template>

<script>
// let baseUrl = "http://192.168.0.220:8091";
let baseUrl = "http://122.51.69.142:8091"; //服务器地址

export default {
  data() {
    return {
      title:"请选择商品类型",
      shopname: [], //店铺名称下拉框
      shopnamevalue: "", //店铺名称选中数据
      version: "", //文本内容
    };
  },
  mounted() {
    // this.shop();
    // this.keeper();
    this.getDataList();
  },
  methods: {
    // 进入页面加载
    getDataList() {
      let _this = this;
      _this.$ajax
        .post(`${baseUrl}/pc/getCategoryList`)
        .then(function (res) {
          //请求成功
          let resData = res.data;
          if (resData.code == 200) {
            resData.data.forEach((item) => {
              _this.shopname.push({
                value: item.id,
                label: item.name,
              });
            });
          } else {
            _this.$message.error(resData.msg);
          }
        })
        .catch(function (error) {
          //请求失败
          console.log(error);
        });
    },
    //输入框搜索
    search() {
      let _this = this;
      if (_this.shopnamevalue != "") {
        _this.$ajax
        .post(`${baseUrl}/pc/postSalesService`, {
          action: 1,
          categoryId: _this.shopnamevalue,
        })
        .then(function (res) {
          //请求成功
          let resData = res.data;
          if (resData.code == 200) {
            _this.version = resData.data.content;
            if (_this.version == "") {
              _this.title="本分类无内容，可编辑保存"
            }
          } else {
            _this.$message.error(resData.msg);
          }
        })
        .catch(function (error) {
          //请求失败
          console.log(error);
        });
      }else {
        _this.version="";
         _this.title="请选择商品类型"
      }
      
    },
    preservation() {
      let _this = this;
      if ( _this.shopnamevalue != "") {
        _this.$ajax
        .post(`${baseUrl}/pc/postSalesService`, {
          action: 2,
          categoryId: _this.shopnamevalue,
          content: _this.version,
        })
        .then(function (res) {
          //请求成功
          let resData = res.data;
          if (resData.code == 200) {
            _this.$message.success("保存成功");
          } else {
            _this.$message.error(resData.msg);
          }
        })
        .catch(function (error) {
          //请求失败
          console.log(error);
        });
      }else {
        _this.$message.error("请选择商品类型");
        
      }
      
    },
  },
};
</script>

<style lang="scss">
#Aftermarket {
  h3 {
    margin: 20px 0;
  }
  .details {
    width: 80vw;
    height: 50vh;
    border: 1px solid black;
    margin-top: 15px;
  }
}
</style>